//
//  WWBaseViewController.m
//  SportsWin
//
//  Created by 于洪东 on 2019/5/26.
//  Copyright © 2019 douniwan. All rights reserved.
//

#import "WWBaseViewController.h"

@interface WWBaseViewController ()

// 返回按钮
@property (nonatomic,strong) UIButton *backButton;

@end

@implementation WWBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 防止子类重写，这里不要用setupUI
    [self setupBaseUI];
}

-(void)dealloc{
    
    DEF_DEBUG(@"%@释放了",self);
}


#pragma mark - ♻️life cycle

#pragma mark - 🔄overwrite

#pragma mark - 🚪public
-(void)hideBackButton{
    self.backButton.hidden = YES;
}

-(void)hideNavigationBar{
    [self.navigationController setNavigationBarHidden:YES];
}

-(void)showNavigationBar{
    [self.navigationController setNavigationBarHidden:NO];
}

-(void)setNavigationBarColor:(UIColor *)color{
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:NTMainColor] forBarMetrics:UIBarMetricsDefault];
}

-(void)setNavigationBarTitleColor:(UIColor *)color{
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : color}];
}

#pragma mark - 🍐delegate

#pragma mark - ☎️notification

#pragma mark - 🎬event response
-(void)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 🔒private

#pragma mark - 🌲setupUI

-(void)setupBaseUI{
    
    self.view.backgroundColor = NTBackGroundColor;
    
    [self setNavigationBarColor:NTMainColor];
    [self setNavigationBarTitleColor:[UIColor whiteColor]];
    
    // 设置导航栏透明，标识布局在屏幕的左上角开始
    // 因为导航栏设置背景图片后，所有的内容视图都下移了导航栏的高度
    // 所以要设置这个属性
    self.navigationController.navigationBar.translucent = YES;
    

    self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.backButton.frame = CGRectMake(0, 0*ScaleX, 44*ScaleX, 44*ScaleX);
    [self.backButton setImage:[UIImage imageNamed:@"coin_back_white"] forState:UIControlStateNormal];
    [self.backButton setImage:[UIImage imageNamed:@"coin_back_white"] forState:UIControlStateSelected];
    [self.backButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [self.backButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];

    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithCustomView:self.backButton];
    self.navigationItem.leftBarButtonItem = backItem;

}

#pragma mark - ☸getter and setter

@end
